package com.examples.program;

import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Types;

public class Driver {

	public static final String JDBC_DRIVER = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
	public static final String DB_URL = "jdbc:sqlserver://localhost;databasename=EMP";
	public static final String DB_USERNAME = "sa";
	public static final String DB_PASSWORD = "123";

	static {
		try {
			Class.forName(JDBC_DRIVER);
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		}
	}

	public static void main(String[] args) {
		Connection connection = null;
		CallableStatement statement = null;
		try {
			connection = DriverManager.getConnection(DB_URL, DB_USERNAME, DB_PASSWORD);
			final String sqlCmd = "{call SP_Employees_GetEmployeeNameById(?,?)}";
			statement = connection.prepareCall(sqlCmd);
			statement.setInt(1, 110);
			statement.registerOutParameter(2, Types.NVARCHAR);
			statement.execute();
			String name = statement.getString(2);
			System.out.println(name);
		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			try {
				if (statement != null) statement.close();
				if (connection != null) connection.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}

		}
	}
}
